<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","CUCODE");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_setup_ar.php";
$FileTemplate  = "ais_setup_ar_list.html";
$TableName     = "tbldebtur";
$SubHeaderTitle= "Setup Account Receivable";
$PageSize      = 10 ;
$HTMLGridList  = "CustomerGrid";
//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

//Initiate Database Table For Search;
$FNama = GetParam("CustomerSearch","");
$FType = GetParam("customerTypeSearch","");
//$FSkada = GetParam("skadaSearch","");
//$FDept = GetParam("deptSearch","");

//******* DATABASE FORM QUERY ***********
$SQL = "SELECT * FROM $TableName ";
$SQLCount = "SELECT count(*) FROM $TableName ";

//Retrieve Parameter from search


if ($FNama) {
	$CustomWhere = " $TableName.CUNAME like '".$FNama."%'";
	if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
	else $WHERE = $CustomWhere;
}

if (strlen($WHERE)) {
	$SQL = $SQL." WHERE ".$WHERE;
	$SQLCount = $SQLCount." WHERE ".$WHERE;
}
else $SQL = $SQL;

//Select Customer 
//$SQLDept = "SELECT * FROM tbldept";

//******* SHOW FORM CONTENT *********
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);


$PageNum = 1;
if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

//Default value
if (!isset($_GET)) $_GET=&$HTTP_GET_VARS ;
if (isset($_GET['PageNum'])) {
  $PageNum = $_GET['PageNum'] ;
} else {
    $PageNum = 1 ;
}

//Default value
if (isset($_GET['RecCnt'])) {
  $RecCnt = intval($_GET['RecCnt']) ;
} else {
    $RecCnt = -1 ;
} 
$Paging = GetQueryString("QueryString",array("PageNum"));
$TBS->MergeBlock("bln",$KEY);
$RecCnt = $TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
//$TBS->MergeBlock("deptblk",$DBMysql,$SQLDept);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName,$TableName;	
	for ($x=1;$x<=$PageSize;$x++) {				
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("$TableName",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>